package com.device.grant.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.device.grant.dao.BaseDao;
import com.device.grant.dao.IemployeeDao;
import com.device.grant.pojo.IEmployee;
import com.device.grant.utils.ColumnCompator;
import com.device.grant.utils.SQLUtils2;

@Repository("iemployeeDao")
public class IemployeeDaoImpl extends BaseDao<IEmployee> implements IemployeeDao {

	private static final String	ID		= "empID";

	private static final String	TABLE	= "IEmployee";

	public boolean addIemployee(IEmployee employee) {
		return super.insert(TABLE, ID, employee);
	}

	public Integer getQueryCount(Map<String, Object> params, List<String> blearParams, Map<String, ColumnCompator> compators) {
		Map<String, Object> map = SQLUtils2.generalCountSQLForCompare(TABLE, ID, params, blearParams, compators);

		return simpleJdbcTemplate.queryForInt(map.get(SQLUtils2.SQL).toString(), (Object[]) map.get(SQLUtils2.PARAMS));
	}

	public boolean updateIemployee(Map<String, Object> changeInfos, Map<String, Object> conditions) {
		return super.update(TABLE, changeInfos, conditions);
	}

	public List<IEmployee> queryIemployees(Integer page, Integer rows, Map<String, Object> conditions, List<String> blearParams,
			Map<String, ColumnCompator> compators, String orderBy) {
		String sql = SQLUtils2.genearlQuerySQLForCompareAndNotIn(TABLE, ID, page, rows, conditions, blearParams, compators, orderBy);

		return super.queryInSQL(sql);
	}

	public IEmployee getIemployee(Map<String, Object> conditions) {
		return super.get(TABLE, conditions);
	}

	public List<IEmployee> queryEmployeeSInIds(Set<Integer> ids) {
		return super.queryInKeys(TABLE, ID, null, ids);
	}

	public List<IEmployee> queryEmployeeSInEmpNos(Set<String> empNos) {
		return super.queryInKeys(TABLE, "EmpNO", null, empNos);
	}

	public boolean reviewGroupRegister(Map<String, Object> changeInfos, Map<String, Object> conditions, Integer exits) {
		boolean flag = false;

		Map<String, Object> resetChangeInfo = new HashMap<String, Object>();
		resetChangeInfo.put("empType", 2);

		Map<String, Object> resetConditions = new HashMap<String, Object>();
		resetConditions.put("empType", 3);
		resetConditions.put("deptID", conditions.get("deptID"));
		resetConditions.put("isCheck", 1);

		if (exits.equals(1)) {
			if (super.update(TABLE, resetChangeInfo, resetConditions)) {
				flag = super.update(TABLE, changeInfos, conditions);
			}
		}
		else {
			flag = super.update(TABLE, changeInfos, conditions);
		}

		return flag;
	}

}
